<?php

include_once "function_xml_basic.php";
include_once "function_xml_atom.php";

$root_path = "/MINI/LOG/CONFIGS";
$syslog_conf = "/usr/local/etc/syslog.conf";

function GetXmlLogServerInfoList()
{
	global $root_path;
	$query_string = $root_path. "/CONFIG";
        $key_array = array("Name", "ServerAddress","ServerPort", "Enabled");
        return GetAttributList($query_string, $key_array);
}
/*$ret_array = GetXmlLogServerInfoList();
foreach ($ret_array as $i)
{
	print $i["ServerAddress"];
	print $i["ServerPort"];
}*/

function SetXmlLogServerInfo($in_array)
{
        global $root_path;
        $query_string = $root_path. "/CONFIG[1]";

        EditAllAttrOfNode($query_string, $in_array);

	ApplySysLogConfig();
}

function ApplySysLogConfig()
{
	global $syslog_conf;
	global $root_path;

	$handle = fopen($syslog_conf, "a+");

	$ret_array = GetXmlLogServerInfoList();
	$ret = $ret_array[0];
	/*
	foreach ($ret_array as $ret)
	{
		$write_string = "*.*		@". $ret['ServerAddress']. ":". $ret['ServerPort']. "\n";
		
		if (fwrite($handle, $write_string) == FALSE)
		{
			return ;
		}
	}
	*/
	$command_write = 'echo "daemon.info     /var/log/log.txt" > '. $syslog_conf. ';'.
			 'echo "daemon.notice   /var/log/log.txt" >>'. $syslog_conf. ';'.
			 'echo " *.*            @'. $ret['ServerAddress']. ':'. $ret['ServerPort']. '" >> '. $syslog_conf;
	$command_string = "/bin/kill -SIGHUP `cat /var/run/syslogd.pid` ";

	//print $command_write;
	shell_exec ($command_write);
	shell_exec ($command_string);
}

?>
